package com.ly.mpayment.persist.service.platformaccount;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.ly.mpayment.core.util.Config;
import com.ly.mpayment.core.util.DateUtils;
import com.ly.mpayment.persist.entity.PlatFormAccount;
import com.ly.mpayment.persist.hibernate.Page;
import com.ly.mpayment.persist.service.AbstractService;

@Service
public class PlatformAccountServiceImpl extends AbstractService<PlatFormAccount, Serializable> implements IPlatformAccountService {

	@Override
	public boolean addPlatformaccount(PlatFormAccount plat) {
		if(plat != null){
			this.saveOrUpdate(plat);
			return true;
		}
		return false;
	}

	@Override
	public boolean updatePlatformaccount(PlatFormAccount plat) {
		if(plat != null){
			this.saveOrUpdate(plat);
			return true;
		}
		return false;
	}

	@Override
	public PlatFormAccount findById(String id) {
		return this.findUnique("select p from PlatFormAccount p where p.status = 1 and p.platformuuid = ?", id);
	}

	@Override
	public Page<PlatFormAccount> findPagePlatformaccount(Map<String, Object> parameters, int start, int pageSize) {
		return this.findPageByNamed("select p from PlatFormAccount p where p.status = 1 order by p.platformname ", parameters, start, pageSize);
	}

//	@Override
//	public PlatFormAccount findByUserUuId(String uuid) {
//		return this.findUnique("select p from PlatFormAccount p left join fetch p.userAccount u  where p.status = 1 and u.useruuid = ?", uuid);
//	}
	
	public PlatFormAccount findByAccount(){
		return this.findUnique("select p from PlatFormAccount p where p.status = 1");
	}

	@Override
	public PlatFormAccount addPlatformaccount() {
		PlatFormAccount plat = new PlatFormAccount();
		plat.setCreatetime(DateUtils.getNowDate());
		plat.setPlatformamount(BigDecimal.ZERO);
		plat.setStatus(Config.publicStatus[1]+"");
		plat.setPlatformname(Config.AccountName);
		return this.saveOrUpdate(plat);
	}

}
